<?

Class SystemModule{
    var $_connect;
    var $error;
    function SystemModule() {
        $this->_connect = new Dataconnection();
        $this->error="";
    }
    function gets(){
        $SQLCommand="
        SELECT
            *
        FROM
            `settings`
        ";
        
        $data=$this->_connect->executeSQL($SQLCommand);
        $this->error.=$this->_connect->error;
        $result=array();
        if($data!=null ){
            while ($row=$data->fetch_array())
                $result[$row["name"]]= $row["value"];
            return $result;
        }
        return null;
    }
    function login($u,$p){
        //$p=md5($p);
        $SQLCommand="
        select * 
        from `account` where `username`='$u' and `password`='$p'
        ";
        $data=$this->_connect->executeSQL($SQLCommand);
        $this->error.=$this->_connect->error;
        if($data!=null ) {
            $row=$data->fetch_array();
            if(isset($row["id"])){
            	$_SESSION[ "USER"] = $row;
                return true;
            }else{
            	return false;
            }
            
        }
        return false;
    }
    function check($e){
        $e=str_replace("'","\'",str_replace("\\","\\\\",$e));
        $SQLCommand="
        select * 
        from `_account` where `mail`='$e'
        ";
        $data=$this->_connect->executeSQL($SQLCommand);
        $this->error.=$this->_connect->error;
        if($data!=null ) {
            $row=$data->fetch_array();
            if($row["id"]!=""){
                return true;
            }else{
            	return false;
            }
            
        }
        return false;
    }
    function insertAccount($name,$mail,$pass){
        $SQLCommand="
        insert 
            `_account`(
                        `username`,`name`,`password`,`mail`,`i`
            )
            values(
                        '$name','$name','$pass','$mail',now()
            )
        ";
        $n=$this->_connect->executeNoneSQL($SQLCommand);
        $this->error.=$this->_connect->error;
        if($n==1) {
            return true;
        }
        return false;
    }
    function updateSetting($para,$value){
        $SQLCommand="
        UPDATE 
            `settings`
        SET `value`='$value'
        WHERE `name`='$para'
        ";
        $n=$this->_connect->executeNoneSQL($SQLCommand);
        $this->error.=$this->_connect->error;
        if($n==1) {
            return true;
        }
        return false;
    }
}
?>